﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace PerpheralDevice.LeadShine {
    public class LeadShineWapper {
        private static int mfBoardCount;
        public static int BoardCount { 
            get {
                if (mfBoardCount > 0) {
                    return mfBoardCount;
                }
                return Init();
            }
        }
        //板卡系统是否                 
        private static bool mHasInitHW = false;
        [MethodImpl(MethodImplOptions.Synchronized)]
        public static int Init() {
            if (!mHasInitHW) {
                mfBoardCount = LeadShine.LTDMC.dmc_board_init();
                if (mfBoardCount <= 0 || mfBoardCount > 8) {
                    //Serilog.Log.Error("运动控制卡初始化失败");
                }
                ushort refNum = 0;
                ushort[] cardIdList = new ushort[8];
                uint[] cardTypeList = new uint[8];
                short res = LTDMC.dmc_get_CardInfList(ref refNum, cardTypeList, cardIdList);
                if (res != 0) {
                    //Serilog.Log.Error("获取运动控制卡信息失败");
                }
                mHasInitHW = true;
            }

            return mfBoardCount;
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        public static void Shut() {
            if (mHasInitHW) {
                LeadShine.LTDMC.dmc_board_close();
                mHasInitHW = false;
            }
            mfBoardCount = 0;
        }

    }
}
